You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
우선, 여러 문제에 대한 깔끔한 솔루션을 제출하셨네요! 전체적으로 가독성도 좋고, 각 문제에 적합한 접근법을 잘 선택하셨습니다. 몇 가지 개선 및 피드백을 드리자면:
시간/공간 복잡도 명시 요청
각 솔루션에 시간과 공간 복잡도를 명시하시면 리뷰어가 성능 측면을 빠르게 파악하는 데 도움이 됩니다. 예를 들어, containsDuplicate는 TC: O(n), SC: O(n)으로 명확하게 표기하는 것이 좋습니다.
containsDuplicate distinct()와 count()를 이용했는데, 이는 깔끔하고 직관적입니다. 하지만, HashSet을 이용하는 것도 O(n) 시간에 충분히 가능하니 참고하세요.
예시:
// TC: O(n), SC: O(n)Set<Integer> set = newHashSet<>();
for (intnum : nums) {
if (!set.add(num)) returntrue;
}
returnfalse;
houseRobber
DP 접근법은 적절합니다. 다만, 마지막 return 부분에서 Math.max(dp[nums.length], dp[nums.length-1])는 필요 없어요. 일반적으로 dp[nums.length]이 가장 큰 값이 될 겁니다.
또한, for 루프 조건이 i=2부터인데, i=1부터 시작하는 것도 고려해 볼 수 있습니다.
추천: 초기값 세팅 후, for(i=2; i<=nums.length; i++)로 진행하는 것도 직관적입니다.
시간/공간 복잡도:
// TC: O(n), SC: O(n)
longestConsecutive
효율적이고, set을 통한 O(n) 해결책이 잘 구현되어 있습니다. completeSet을 이용한 중복 체크도 좋습니다.
다만, getSequence를 호출할 때, 해당 숫자 연속성을 이미 체크했기 때문에, 중복 체크를 별도로 할 필요는 없습니다.
가독성을 위해 getSequence 이름 대신 countConsecutive(int start, Set<Integer> set)으로 명명하는 것도 고려하세요.
topKFrequent
연결 리스트를 이용한 버킷 정렬 방식이 적절하며, 시간복잡도도 O(n)으로 잘 설계됐습니다.
Node와 NodeList 클래스를 활용하는 구조도 깔끔하고, 명확합니다.
다만, HashMap 대신 TreeMap을 사용하면 정렬이 보장되지만, 이 경우 시간복잡도는 증가하니, 현재 방식이 더 적합합니다.
추천: 답안에 // TC: O(n) 및 // SC: O(n)를 표기하면 좋겠습니다.
twoSum
HashMap을 이용한 방식이 최적입니다.
코딩도 깔끔하고, 이해하기 쉽습니다.
시간복잡도는 O(n), 공간복잡도도 O(n)임을 명시하면 좋겠어요.
전반적인 팁:
각 솔루션에 시간/공간 복잡도를 명시하는 습관을 들이세요.
변수명, 메서드명은 직관적이고 일관되게 유지하시면 가독성이 더 좋아집니다.
일부 문제에서는 초기값 세팅을 조금 더 명확하게 하는 것도 좋은 습관입니다.
전체적으로 훌륭한 답안입니다! 계속해서 다양한 문제를 도전하며 더 나은 성능과 가독성을 추구하세요.
The reason will be displayed to describe this comment to others. Learn more.
for문 안에 if문을 작성하고 싶지 않아서 dp[0]이라는 빈 공간을 만들었는데, 지금 보니 뭔가 가독성이 살짝 떨어지고, 실수를 했을 때 발견하기 쉽지 않을 것 같네요. nayeongdev님의 말씀대로, 원 배열 길이를 따르는 형식이 좀 더 좋은 것 같습니다. 좋은 피드백 감사합니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!